class Solution {
public:
    int findSmallestInteger(vector<int>& nums, int value) {
        vector<int> table(value);
        unordered_map<int, int> hash;
        for (int i = -1; i > -value; i--) hash[i] = i + value;
        for (int num : nums) {
            if (num >= 0) table[num % value]++;
            else table[hash[num % value]]++;
        }
        int ret = 0, n = nums.size();
        while (n--) {
            for (int i = 0; i < value; i++)
                if (table[i]-- > 0) ret++;
                else return ret;
        }
        return ret;
    }
};